var app = getApp();
const util = require('../../utils/util.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isCollection: {
      type: Boolean,
      value: false
    },
    zid: {
      type: Number,
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    inUrl: "images/collect_h.png",
    onUrl: "images/collect.png"
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /*本地缓存法
    onCollectiontap: function(e) {
      let id = e.currentTarget.dataset.id;
      let videosCollected = wx.getStorageSync("_videosCollected");
      let videoCollected = videosCollected[id];
      videoCollected = !videoCollected;
      videosCollected[id] = videoCollected;
      wx.setStorageSync("_videosCollected", videosCollected);
      this.setData({ isCollection: videoCollected });
      wx.showToast({
        title: videoCollected ? '收藏成功' : '取消成功',
      })
    } */ 
    onCollectiontap: function (e){
      let id = e.currentTarget.dataset.id;
      let isc = e.currentTarget.dataset.isc;
      this.setData({ isCollection: !isc });
      if (app.globalData.openid) {
        let data = {
          openid: app.globalData.openid,
          videoId: id,
          ztype: isc ? 9 : 1
        }
        util.http(app.globalData.userOperating, 'POST', data, null)
      }
      wx.showToast({
        title: !isc ? '收藏成功' : '取消成功',
      })
    }

  }

})